<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>构造函数 | Swift 简介</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.1.0">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="gitbook/style.css">
    
    

        
    
    
    <link rel="next" href="./11-lazy.html" />
    
    
    <link rel="prev" href="./09-closure.html" />
    

        
    </head>
    <body>
        
        
    <div class="book" data-level="0.10" data-basepath="." data-revision="Fri Aug 28 2015 04:40:56 GMT+0800 (CST)">
    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Type to search" class="form-control" />
    </div>
    <ul class="summary">
        
        
        
        

        

        
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="./index.html">
                        <i class="fa fa-check"></i>
                        
                        Swift快速入门
                    </a>
                
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.1" data-path="01-playground.html">
            
                
                    <a href="./01-playground.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.1.</b>
                        
                        Playground
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.2" data-path="02-var_and_let.html">
            
                
                    <a href="./02-var_and_let.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.2.</b>
                        
                        变量和常量
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.3" data-path="03-optional.html">
            
                
                    <a href="./03-optional.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.</b>
                        
                        Optional可选值
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.4" data-path="04-control_flow.html">
            
                
                    <a href="./04-control_flow.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.4.</b>
                        
                        控制流
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.5" data-path="05-loop.html">
            
                
                    <a href="./05-loop.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.5.</b>
                        
                        循环
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.6" data-path="06-string.html">
            
                
                    <a href="./06-string.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.6.</b>
                        
                        字符串
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.7" data-path="07-collection.html">
            
                
                    <a href="./07-collection.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.7.</b>
                        
                        集合
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.8" data-path="08-func.html">
            
                
                    <a href="./08-func.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.8.</b>
                        
                        函数
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.9" data-path="09-closure.html">
            
                
                    <a href="./09-closure.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.9.</b>
                        
                        闭包
                    </a>
                
            
            
        </li>
    
        <li class="chapter active" data-level="0.10" data-path="10-init_func.html">
            
                
                    <a href="./10-init_func.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.10.</b>
                        
                        构造函数
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.11" data-path="11-lazy.html">
            
                
                    <a href="./11-lazy.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.11.</b>
                        
                        懒加载 &amp; didSet
                    </a>
                
            
            
        </li>
    
        <li class="chapter " data-level="0.12" data-path="12-ats.html">
            
                
                    <a href="./12-ats.html">
                        <i class="fa fa-check"></i>
                        
                            <b>0.12.</b>
                        
                        ATS
                    </a>
                
            
            
        </li>
    

            </ul>
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                Published with GitBook
            </a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Table of Contents"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="Search"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="Font Settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">Serif</button>
        <button type="button" data-font="1" class="button">Sans</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">White</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">Sepia</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">Night</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="Share"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    Share on Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    Share on Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    Share on Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    Share on Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    Share on Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="./" >Swift 简介</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0">&#x6784;&#x9020;&#x51FD;&#x6570;</h1>
<h2 id="%E8%AE%BE%E7%BD%AE-optional-%E5%B1%9E%E6%80%A7">&#x8BBE;&#x7F6E; Optional &#x5C5E;&#x6027;</h2>
<ul>
<li>&#x81EA;&#x5B9A;&#x4E49; <code>Person</code> &#x5BF9;&#x8C61;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>: <span class="hljs-title">NSObject</span> </span>{

    <span class="hljs-keyword">var</span> name: <span class="hljs-type">String</span>
    <span class="hljs-keyword">var</span> age: <span class="hljs-type">Int</span>
}
</code></pre>
<ul>
<li>&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x4F1A;&#x62A5;&#xFF1A;&#x201C;&#x5B58;&#x50A8;&#x6027;&#x5C5E;&#x6027;&#x6CA1;&#x6709;&#x521D;&#x59CB;&#x5316;&#x503C;&#x201D;</li>
<li>&#x89E3;&#x51B3;&#x529E;&#x6CD5;&#xFF1A;&#x5C06;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x8BBE;&#x7F6E;&#x4E3A; <code>Optional</code></li>
</ul>
<pre><code class="lang-swift"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>: <span class="hljs-title">NSObject</span> </span>{
    <span class="hljs-keyword">var</span> name: <span class="hljs-type">String</span>?
    <span class="hljs-keyword">var</span> age: <span class="hljs-type">Int</span>?
}
</code></pre>
<ul>
<li>&#x6D4B;&#x8BD5;&#x7C7B;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">let</span> p = <span class="hljs-type">Person</span>()
p.name = <span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>
p.age = <span class="hljs-number">18</span>

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;<span class="hljs-subst">\(p.name)</span> --- <span class="hljs-subst">\(p.age)</span>&quot;</span>)
</code></pre>
<ul>
<li>&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#xFF1A;Optional(&quot;&#x5F20;&#x4E09;&quot;) --- Optional(18)</li>
</ul>
<h2 id="%E5%88%A9%E7%94%A8-init-%E5%87%BD%E6%95%B0%E4%B8%BA%E5%B1%9E%E6%80%A7%E5%88%9D%E5%A7%8B%E5%8C%96">&#x5229;&#x7528; <code>init</code> &#x51FD;&#x6570;&#x4E3A;&#x5C5E;&#x6027;&#x521D;&#x59CB;&#x5316;</h2>
<ul>
<li>&#x5982;&#x679C;&#x5728; <code>init</code> &#x4E2D;&#x7ED9;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x521D;&#x59CB;&#x503C;&#xFF0C;&#x5219;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x4E0D;&#x7528;&#x53EF;&#x9009;&#x9879;</li>
<li>&#x56E0;&#x4E3A;&#xFF1A;&#x53EA;&#x6709;&#x8C03;&#x7528;&#x4E86; init &#x51FD;&#x6570;&#x4E4B;&#x540E;&#xFF0C;&#x624D;&#x80FD;&#x786E;&#x4FDD;&#x5BF9;&#x8C61;&#x53EF;&#x7528;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>: <span class="hljs-title">NSObject</span> </span>{
    <span class="hljs-keyword">var</span> name: <span class="hljs-type">String</span>
    <span class="hljs-keyword">var</span> age: <span class="hljs-type">Int</span>

    <span class="hljs-keyword">override</span> <span class="hljs-keyword">init</span>() {
        name = <span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>
        age = <span class="hljs-number">19</span>
    }
}
</code></pre>
<h2 id="%E9%87%8D%E8%BD%BD%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0">&#x91CD;&#x8F7D;&#x6784;&#x9020;&#x51FD;&#x6570;</h2>
<ul>
<li>Swift &#x4E2D;&#x652F;&#x6301;&#x51FD;&#x6570;&#x91CD;&#x8F7D;&#xFF0C;&#x540C;&#x6837;&#x7684;&#x51FD;&#x6570;&#x540D;&#xFF0C;&#x4E0D;&#x4E00;&#x6837;&#x7684;&#x53C2;&#x6570;&#x7C7B;&#x578B;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">init</span>(name: <span class="hljs-type">String</span>, age: <span class="hljs-type">Int</span>) {
    <span class="hljs-keyword">self</span>.name = name
    <span class="hljs-keyword">self</span>.age = age
}
</code></pre>
<h3 id="%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9">&#x6CE8;&#x610F;&#x4E8B;&#x9879;</h3>
<ul>
<li>&#x5982;&#x679C;&#x91CD;&#x8F7D;&#x4E86;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x4F46;&#x662F;&#x6CA1;&#x6709;&#x5B9E;&#x73B0;&#x9ED8;&#x8BA4;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x5219;&#x7CFB;&#x7EDF;&#x4E0D;&#x518D;&#x63D0;&#x4F9B;&#x9ED8;&#x8BA4;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;</li>
</ul>
<h2 id="kvc-%E5%AD%97%E5%85%B8%E8%BD%AC%E6%A8%A1%E5%9E%8B%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0">KVC &#x5B57;&#x5178;&#x8F6C;&#x6A21;&#x578B;&#x6784;&#x9020;&#x51FD;&#x6570;</h2>
<pre><code class="lang-swift"><span class="hljs-keyword">init</span>(dict: [<span class="hljs-type">String</span>: <span class="hljs-type">AnyObject</span>]) {
    setValuesForKeysWithDictionary(dict)
}
</code></pre>
<ul>
<li>&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x4F1A;&#x62A5;&#x9519;</li>
<li>&#x539F;&#x56E0;&#xFF1A;&#x4F7F;&#x7528; KVC &#x4E3A;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x6570;&#x503C;&#x524D;&#xFF0C;&#x9700;&#x8981;&#x786E;&#x4FDD;&#x5BF9;&#x8C61;&#x5DF2;&#x7ECF;&#x88AB;&#x521D;&#x59CB;&#x5316;</li>
<li>&#x6DFB;&#x52A0; <code>super.init()</code> &#x540C;&#x6837;&#x4F1A;&#x62A5;&#x9519;</li>
<li>&#x539F;&#x56E0;&#xFF1A;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#xFF0C;&#x4E0D;&#x4F1A;&#x521D;&#x59CB;&#x5316;&#x672C;&#x7C7B;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;</li>
<li>&#x89E3;&#x51B3;&#x529E;&#x6CD5;&#xFF1A;&#x5C06;&#x5C5E;&#x6027;&#x4FEE;&#x6539;&#x4E3A;&#x53EF;&#x9009;&#x9879;</li>
<li>&#x4FEE;&#x6539;&#x540E;&#x7684;&#x4EE3;&#x7801;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">var</span> name: <span class="hljs-type">String</span>?
<span class="hljs-keyword">var</span> age: <span class="hljs-type">Int</span>?

<span class="hljs-keyword">init</span>(dict: [<span class="hljs-type">String</span>: <span class="hljs-type">AnyObject</span>]) {
    <span class="hljs-keyword">super</span>.<span class="hljs-keyword">init</span>()

    setValuesForKeysWithDictionary(dict)
}
</code></pre>
<blockquote>
<p>&#x8FD0;&#x884C;&#x6D4B;&#x8BD5;&#xFF0C;&#x4ECD;&#x7136;&#x4F1A;&#x62A5;&#x9519;</p>
</blockquote>
<p>&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#xFF1A;<code>this class is not key value coding-compliant for the key age.</code></p>
<ul>
<li>&#x539F;&#x56E0;&#xFF1A;&#x5728; Swift &#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x5BF9;&#x8C61;&#x7684;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5C5E;&#x6027;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x5219;&#x5728;&#x521D;&#x59CB;&#x5316;&#x65F6;&#xFF0C;&#x4E0D;&#x4F1A;&#x4E3A;&#x8BE5;&#x5C5E;&#x6027;&#x5206;&#x914D;&#x7A7A;&#x95F4;</li>
<li>&#x89E3;&#x51B3;&#x529E;&#x6CD5;&#xFF1A;&#x7ED9;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x8BBE;&#x7F6E;&#x521D;&#x59CB;&#x503C;</li>
<li>&#x4FEE;&#x6539;&#x540E;&#x7684;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-keyword">var</span> name: <span class="hljs-type">String</span>?
<span class="hljs-keyword">var</span> age: <span class="hljs-type">Int</span> = <span class="hljs-number">0</span>

<span class="hljs-keyword">init</span>(dict: [<span class="hljs-type">String</span>: <span class="hljs-type">AnyObject</span>]) {
    <span class="hljs-keyword">super</span>.<span class="hljs-keyword">init</span>()

    setValuesForKeysWithDictionary(dict)
}
</code></pre>
<blockquote>
<p>&#x63D0;&#x793A;&#xFF1A;&#x5728;&#x5B9A;&#x4E49;&#x7C7B;&#x65F6;&#xFF0C;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5C5E;&#x6027;&#x4E00;&#x5B9A;&#x8981;&#x8BBE;&#x7F6E;&#x521D;&#x59CB;&#x503C;&#xFF0C;&#x5426;&#x5219;&#x65E0;&#x6CD5;&#x6B63;&#x5E38;&#x4F7F;&#x7528; KVC &#x8BBE;&#x7F6E;&#x6570;&#x503C;</p>
</blockquote>
<h2 id="%E5%AD%90%E7%B1%BB%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0">&#x5B50;&#x7C7B;&#x6784;&#x9020;&#x51FD;&#x6570;</h2>
<ul>
<li>&#x81EA;&#x5B9A;&#x4E49;&#x5B50;&#x7C7B;&#x65F6;&#xFF0C;&#x9700;&#x8981;&#x5728;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x9996;&#x5148;&#x4E3A;&#x672C;&#x7C7B;&#x5B9A;&#x4E49;&#x7684;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x521D;&#x59CB;&#x503C;</li>
<li>&#x7136;&#x540E;&#x518D;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x7236;&#x7C7B;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x5C5E;&#x6027;</li>
</ul>
<pre><code class="lang-swift"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span>: <span class="hljs-title">Person</span> </span>{

    <span class="hljs-keyword">var</span> no: <span class="hljs-type">String</span>

    <span class="hljs-keyword">override</span> <span class="hljs-keyword">init</span>() {
        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Student init&quot;</span>)

        no = <span class="hljs-string">&quot;001&quot;</span>

        <span class="hljs-keyword">super</span>.<span class="hljs-keyword">init</span>()
    }
}
</code></pre>
<h2 id="convenience-%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0">convenience &#x6784;&#x9020;&#x51FD;&#x6570;</h2>
<ul>
<li>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x90FD;&#x662F;&#x6307;&#x5B9A;&#x6784;&#x9020;&#x51FD;&#x6570; <code>Designated</code></li>
<li><code>convenience</code> &#x5173;&#x952E;&#x5B57;&#x4FEE;&#x9970;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x4FBF;&#x6377;&#x6784;&#x9020;&#x51FD;&#x6570;</li>
<li>&#x4FBF;&#x6377;&#x6784;&#x9020;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE; <code>nil</code></li>
<li>&#x53EA;&#x6709;&#x4FBF;&#x6377;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E2D;&#x53EF;&#x4EE5;&#x8C03;&#x7528; <code>self.init()</code></li>
<li>&#x4FBF;&#x6377;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E0D;&#x80FD;&#x88AB;&#x7EE7;&#x627F;</li>
</ul>
<pre><code class="lang-swift">convenience <span class="hljs-keyword">init</span>?(age: <span class="hljs-type">Int</span>) {
    <span class="hljs-keyword">if</span> age &gt; <span class="hljs-number">20</span> &amp;&amp; age &lt; <span class="hljs-number">60</span> {
        <span class="hljs-keyword">self</span>.<span class="hljs-keyword">init</span>()
        <span class="hljs-keyword">self</span>.age = age

        <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">nil</span>
}
</code></pre>
<h2 id="%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E5%B0%8F%E7%BB%93">&#x6784;&#x9020;&#x51FD;&#x6570;&#x5C0F;&#x7ED3;</h2>
<ul>
<li>&#x6307;&#x5B9A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x5FC5;&#x987B;&#x8C03;&#x7528;&#x5176;&#x76F4;&#x63A5;&#x7236;&#x7C7B;&#x7684;&#x7684;&#x6307;&#x5B9A;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF08;&#x9664;&#x975E;&#x6CA1;&#x6709;&#x7236;&#x7C7B;&#xFF09;</li>
<li>&#x4FBF;&#x6377;&#x6784;&#x9020;&#x51FD;&#x6570;&#x5FC5;&#x987B;&#x8C03;&#x7528;&#x540C;&#x4E00;&#x7C7B;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x5176;&#x4ED6;&#x6784;&#x9020;&#x51FD;&#x6570;</li>
<li>&#x4FBF;&#x6377;&#x6784;&#x9020;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE; <code>nil</code></li>
<li>&#x4FBF;&#x6377;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E0D;&#x80FD;&#x88AB;&#x7EE7;&#x627F;</li>
</ul>
<p><img src="images/&#x6784;&#x9020;&#x51FD;&#x6570;.png" alt=""></p>
<h2 id="%E6%9E%90%E6%9E%84%E5%87%BD%E6%95%B0-deinit">&#x6790;&#x6784;&#x51FD;&#x6570; <code>deinit</code></h2>
<ul>
<li>&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x88AB;&#x91CA;&#x653E;&#x4E4B;&#x524D;&#xFF0C;&#x6790;&#x6784;&#x51FD;&#x6570;&#x4F1A;&#x7ACB;&#x5373;&#x88AB;&#x81EA;&#x52A8;&#x8C03;&#x7528;</li>
<li>&#x7C7B;&#x4F3C;&#x4E0E; OC &#x7684; <code>dealloc</code></li>
<li>&#x4E00;&#x822C;&#x5728;&#x6790;&#x6784;&#x65B9;&#x6CD5;&#x4E2D;&#x8FDB;&#x884C;&#x8D44;&#x6E90;&#x7684;&#x91CA;&#x653E;</li>
<li>&#x4E0D;&#x5141;&#x8BB8;&#x4E3B;&#x52A8;&#x8C03;&#x7528;&#x6790;&#x6784;&#x51FD;&#x6570;</li>
<li>&#x5982;&#x679C;&#x662F;&#x7EE7;&#x627F;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x4F1A;&#x5148;&#x8C03;&#x7528;&#x672C;&#x7C7B;&#x7684;&#x6790;&#x6784;&#x51FD;&#x6570;&#xFF0C;&#x518D;&#x987A;&#x5E8F;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x6790;&#x6784;&#x51FD;&#x6570;&#xFF0C;&#x4EE5;&#x786E;&#x4FDD;&#x6240;&#x6709;&#x5C5E;&#x6027;&#x5168;&#x90E8;&#x88AB;&#x91CA;&#x653E;</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="./09-closure.html" class="navigation navigation-prev " aria-label="Previous page: 闭包"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="./11-lazy.html" class="navigation navigation-next " aria-label="Next page: 懒加载 &amp; didSet"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="gitbook/app.js"></script>

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
